//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System.Text.RegularExpressions;

namespace CommunityServer.Components
{
	public interface ITextToken
	{
		string Pattern {get;}
		string FormatText(string text);
	}

	public class TextToken : ITextToken
	{
		private string _token, _link, _text;
		private int _tokenid, _sectionid;
		
		public virtual string Pattern
		{
			get { return "\\[" + Token + "\\]";}
		}

		public int SectionID
		{
			get{ return _sectionid;}
			set{_sectionid = value;}
		}

		public int TokenID
		{
			get{ return _tokenid;}
			set{_tokenid = value;}
		}

		public string Token
		{
			get { return _token;}
			set { _token = value;}
		}


		public string Link
		{
			get { return _link;}
			set { _link = value;}
		}

		public string Text
		{
			get { return _text;}
			set { _text = value;}
		}

		public virtual string FormatText(string textToFormat)
		{
			if(!Globals.IsNullorEmpty(Link))
			{
				return Regex.Replace(textToFormat,Pattern, "<a href=\"" + Link + "\">" + Text + "</a>",RegexOptions.IgnoreCase );
			}
			else
			{
				return Regex.Replace(textToFormat,Pattern, Text, RegexOptions.IgnoreCase );	
			}
		}


	}
}